package com.botarena.server.servlets.http;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.botarena.server.services.BattleProcessor;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class ProcessOneBattleServlet extends HttpServlet {

	private static final long serialVersionUID = 2555991633456777L;

	@Override
	public void doGet(final HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		Key bot1Key = KeyFactory.stringToKey(request.getParameter("bot1"));
		Key bot2Key = KeyFactory.stringToKey(request.getParameter("bot2"));
		Key contestKey = KeyFactory.stringToKey(request.getParameter("contest"));
		
		BattleProcessor.performBattleBetween(bot1Key, bot2Key, contestKey);
		
		response.getOutputStream().println("OK");
	}
}